<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>

<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>首页</title>
		<link rel="stylesheet" href="css/page.css" />
		
		<script type="text/javascript" src="JS/jquery-3.4.1.js" ></script>
		<%@ include file="/manager_js.jsp" %>
		<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
	</head>

	<body>
		
		<div class="left">
			<div class="bigTitle">淘宝后台管理系统</div>
			<div class="lines">
				<div onclick="show3(1)" class="active">审批商家申请</div>
				<div onclick="show3(2)">限制店铺上架</div>
				<div onclick="show3(3)">解除店铺限制</div>
				<div onclick="window.location.href='Login.jsp'">退出登录</div>
				
			</div>
		</div>
		<div class="top">
			<div class="leftTiyle" id="flTitle">审批商家申请</div>
			<div class="thisUser">当前管理员：${user_login.username }</div>
		</div>
		
		
		
		<!-- 审核开始 -->
		  <div class="showapplication_div" id="showapplication_div" style = "display:none;">
			 <table>
        		<thead>
            <tr>
                <th width="100px">店铺头像</td>
                <th width="200px">店铺名称</th>
                <th width="250px">店铺描述</th>
                <th width="150px">
                   	 全选<input type="checkbox" id="j_cbAll" />
                </th>
            </tr>
        </thead>
        <tbody id="j_tb">
        	<c:forEach items="${app1 }" var="n">
	            <tr height="150px">
	                <td ><img src="img/taobaotu.jpg" style = "width:100px;height:100px;"></td>
	                <td >${n.shopname }</td>
	                <td >${n.shopdescribe }</td>
	                <td >
	                    <input type="checkbox" id = "c_${n.shopuser }" name = "${n.shopuser }" class = "checkbox"/>
	                </td>
	            </tr>
        	</c:forEach>

        </tbody>
    		</table>
		<input type = "button" onclick = "addmit(1)" style = "width:100px;height:30px;"value = "批准">
		<input type = "button" onclick = "addmit(2)" style = "width:100px;height:30px;"value = "不批准">
		</div><!-- 审核结束 -->
		
		 
		<!-- 限制开始 -->
		<div class="limitshop_div" id="limitshop_div" style = "display:none;">
			 <table>
        		<thead>
            <tr>
                <th width="100px">店铺头像</th>
                <th width="200px">店铺名称</th>
                <th width="250px">店铺描述</th>
                <th width="150px">
                   	 全选<input type="checkbox" id="j_cbAll" />
                </th>
            </tr>
        </thead>
        <tbody id="j_tb">
        	<c:forEach items="${shop1 }" var="n">
	            <tr height="150px">
	                <td ><img src="${pageContext.request.contextPath }${n.shophead}" style = "width:100px;height:100px;"></td>
	                <td >${n.shopname }</td>
	                <td >${n.shopdescribe }</td>
	                <td >
	                    <input type="checkbox" id = "c_${n.shopid }" name = "${n.shopid }" class = "checkbox"/>
	                </td>
	            </tr>
        	</c:forEach>

        </tbody>
    		</table>
		<input type = "button" onclick = "limit()" style = "width:100px;height:30px;"value = "限制上架">
		</div><!-- 限制结束 -->
		
		
		<!-- 解除限制开始 -->
		<div class="relieveshop_div" id="relieveshop_div" style = "display:none;">
			 <table>
        		<thead>
            <tr>
                <th width="100px">店铺头像</td>
                <th width="200px">店铺名称</th>
                <th width="250px">店铺描述</th>
                <th width="150px">
                   	 全选<input type="checkbox" id="j_cbAll" />
                </th>
            </tr>
        </thead>
        <tbody id="j_tb">
        	<c:forEach items="${shop2 }" var="n">
	            <tr height="150px">
	                <td ><img src="${pageContext.request.contextPath }${n.shophead}" style = "width:100px;height:100px;"></td>
	                <td >${n.shopname }</td>
	                <td >${n.shopdescribe }</td>
	                <td >
	                    <input type="checkbox" id = "c_${n.shopid }" name = "${n.shopid }" class = "checkbox"/>
	                </td>
	            </tr>
        	</c:forEach>

        </tbody>
    		</table>
		<input type = "button" onclick = "relieve()" style = "width:100px;height:30px;"value = "解除限制">
		</div><!-- 解除限制结束 -->
		
<script type="text/javascript">
function limit(){
	$(".checkbox").each(function(){
		if($(this).is(":checked")){
			var shopid = $(this).attr("name")
			$.ajax({
				//记得该路径格式不能写在引用的js文件中
				url : "${pageContext.request.contextPath}/LimitShopServlet",
				async : false,
				type : "post",
				data : {'shopid':shopid},
				dataType : "json",
				success : function(d) {
				}
			});//ajax结束
		}
	})//each over
			window.location.reload()
}//limit function over

function relieve(){
	$(".checkbox").each(function(){
		if($(this).is(":checked")){
			var shopid = $(this).attr("name")
			$.ajax({
				//记得该路径格式不能写在引用的js文件中
				url : "${pageContext.request.contextPath}/RelieveShopServlet",
				async : false,
				type : "post",
				data : {'shopid':shopid},
				dataType : "json",
				success : function(d) {
				}
			});//ajax结束
		}
	})/* each over */
			window.location.reload()
}//relieve function over

function addmit(a){
	$(".checkbox").each(function(){
		if($(this).is(":checked")){
			var shopuser = $(this).attr("name")
			$.ajax({
				//记得该路径格式不能写在引用的js文件中
				url : "${pageContext.request.contextPath}/AppAdmitServlet",
				async : false,
				type : "post",
				data : {'shopuser':shopuser,'agree':a},
				dataType : "json",
				success : function(d) {
					window.location.reload()
				}
			});//ajax结束
		}
	})
}
</script>
		
<script type="text/javascript" charset="UTF-8">
 var all = document.getElementById("j_cbAll");
 var tbody = document.getElementById("j_tb");
 var checkboxs = tbody.getElementsByTagName("input");
 all.onclick = function() {
     for (var i = 0; i < checkboxs.length; i++) {
         var checkbox = checkboxs[i];
         checkbox.checked = this.checked;
     }
 };
 for (var i = 0; i < checkboxs.length; i++) {
     checkboxs[i].onclick = function() {
         var isCheckedAll = true;
         for (var i = 0; i < checkboxs.length; i++) {
             if (!checkboxs[i].checked) {
                 isCheckedAll = false;
                 break;
             }
         }
         all.checked = isCheckedAll;
     };
 }
 </script>
	</body>
</html>